// Logistics/PersonalData/PersonalData.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fieldList: [
      {field_id: 'Nickname', label: '昵称',type: 'splc',is_null: true}
      ,{field_id: 'tel', label: '电话',type: 'splc',is_null: true}
      ,{field_id: 'plate', label: '车牌',type: 'splc',is_null: true}

    ],
    defData:{},
    formData:{},

    //只读标识
    readonly: true,

  },
  bindChange(e){
    console.log(e);
  },
  onSubmit(e){
    let {loginType, openid} = this.data,
      {Nickname,tel,plate} = e.detail.value,
      post = {miniprogram_OpenID: openid,tel,plate}
    if (loginType === 'noLogin') post.Nickname = Nickname;
    let url = 'WXMiniProgram/update_miniprogram_customer_user_inf';
    wx.showLoading({mask: true});
    wx.$post(1,url,post).then(res => {
      if (res.errcode != 0 )return;
      wx.$toast('修改成功！');
      this.setData({readonly: true})
      wx.setStorageSync('user_name',Nickname)
    })
  },

  toggleStatus(){
    this.setData({readonly: false})
  },

  getUserInfo(){
    let url = 'WXMiniProgram/get_miniprogram_customer_user_inf',
      post = {
        // "system_id": 0,
        // "unionid": "string",
        "miniprogram_OpenID": this.data.openid,
        // "offiaccount_OpenID": "string"
      };
    wx.showLoading({mask: true})
    wx.$post(1,url,post).then(res => {
      if (res.errcode != 0) return;
      wx.hideLoading();
      let data = res.data.row;
      this.setData({
        formData: data[0] || {}
      });
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let loginType = wx.getStorageSync('loginType'),
      openid = wx.getStorageSync('openid'),
      obj = {loginType,openid}
    this.setData(obj);
    this.getUserInfo();
    //登录使用的，昵称直接显示用户名，不需要修改
    /*if (loginType === 'login'){
      let userName = wx.getStorageSync('user_name')
      obj = {...obj,
        fieldList: [{field_id: 'Nickname', label: '用户名',type: 'splc',is_null: true,disabled: true}],
        ['formData.Nickname']: userName,
      }
      this.setData(obj);
    }else {
      this.setData(obj);
      this.getUserInfo();
    }*/
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})
